Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

293
Visualizações
Saving selection in ant design table. [React]

So I'm using ant design (antd). I have created a table with custom pagination. Each page change an API call is made to retrieve a new set of data.

I have successfully implemented code that saves my individual checked boxes while changing pages. Example: on the first page i select 3 checkboxes, then i go to the second and check 2 there, then go to the third and check 5 there. My final state amounts to 10 checked boxes and they are successfully displayed as checked on the table itself.

The next thing i want to achieve is the same but using the check all button on the antd table. I want to be able to select all items from the first page, then go to the second one and select all, then third one and select all and have it all saved and displayed across pages in the table.

The state for individual checking and check all should be shared.

My selectedKeys state:

 const [selectedRowKeys, setSelectedRowKeys] = useState([]);

My row selection

  const onSelectChange = (row) => {
    setSelectedRowKeys((prevKeys) => [...prevKeys, row]);
  };
  const rowSelection = {
    selectedRowKeys: selectedRowKeys.map((item) => item.id), //error line
    preserveSelectedRowKeys: true,
    onSelect: (row, selected, selectedRows) => {
      if (selected) {
        onSelectChange(row);
        setSelectedRow(selectedRows);
        
      } else {
        setSelectedRowKeys((prevKeys) =>
          prevKeys.filter((key) => key.id !== row.id)
        );
      }
    },
    onSelectAll: (selected, row, selectedRows) => {
      if (selected) {
        setSelectedRowKeys(row); //not sure im doing the right thing here
        setSelectedRow(selectedRows); 
      } else {
        //dont know what to put here
      }
    },
  };

The problem arrives after i check everything on the first page and go to the second. When i try to check all items there the app breaks and i get errors such as cant read id of undefined in the //error line and pretty much everywhere where i have to map over selectedRowKeys.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda